home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / ncurses-5.3 / ncurses / base / lib_freeall.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  3.6 KB  |  112 lines

  1. /****************************************************************************
  2.  * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
  3.  *                                                                          *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a  *
  5.  * copy of this software and associated documentation files (the            *
  6.  * "Software"), to deal in the Software without restriction, including      *
  7.  * without limitation the rights to use, copy, modify, merge, publish,      *
  8.  * distribute, distribute with modifications, sublicense, and/or sell       *
  9.  * copies of the Software, and to permit persons to whom the Software is    *
  10.  * furnished to do so, subject to the following conditions:                 *
  11.  *                                                                          *
  12.  * The above copyright notice and this permission notice shall be included  *
  13.  * in all copies or substantial portions of the Software.                   *
  14.  *                                                                          *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
  16.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
  17.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
  18.  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
  19.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
  20.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
  21.  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
  22.  *                                                                          *
  23.  * Except as contained in this notice, the name(s) of the above copyright   *
  24.  * holders shall not be used in advertising or otherwise to promote the     *
  25.  * sale, use or other dealings in this Software without prior written       *
  26.  * authorization.                                                           *
  27.  ****************************************************************************/
  28.  
  29. /****************************************************************************
  30.  *  Author: Thomas E. Dickey <dickey@clark.net> 1996,1997                   *
  31.  ****************************************************************************/
  32.  
  33. #include <curses.priv.h>
  34. #include <term_entry.h>
  35.  
  36. #if HAVE_NC_FREEALL
  37.  
  38. #if HAVE_LIBDBMALLOC
  39. extern int malloc_errfd;    /* FIXME */
  40. #endif
  41.  
  42. MODULE_ID("$Id: lib_freeall.c,v 1.20 2002/07/28 00:35:25 tom Exp $")
  43.  
  44. /*
  45.  * Free all ncurses data.  This is used for testing only (there's no practical
  46.  * use for it as an extension).
  47.  */
  48. NCURSES_EXPORT(void)
  49. _nc_freeall(void)
  50. {
  51.     WINDOWLIST *p, *q;
  52.     char *s;
  53.  
  54. #if NO_LEAKS
  55.     _nc_free_tparm();
  56. #endif
  57.     if (SP != 0) {
  58.     while (_nc_windows != 0) {
  59.         /* Delete only windows that're not a parent */
  60.         for (p = _nc_windows; p != 0; p = p->next) {
  61.         bool found = FALSE;
  62.  
  63.         for (q = _nc_windows; q != 0; q = q->next) {
  64.             if ((p != q)
  65.             && (q->win._flags & _SUBWIN)
  66.             && (&(p->win) == q->win._parent)) {
  67.             found = TRUE;
  68.             break;
  69.             }
  70.         }
  71.  
  72.         if (!found) {
  73.             delwin(&(p->win));
  74.             break;
  75.         }
  76.         }
  77.     }
  78.     delscreen(SP);
  79.     }
  80.  
  81.     if (cur_term != 0) {
  82.     _nc_free_termtype(&(cur_term->type));
  83.     free(cur_term);
  84.     }
  85.  
  86.     if ((s = _nc_home_terminfo()) != 0)
  87.     free(s);
  88. #ifdef TRACE
  89.     (void) _nc_trace_buf(-1, 0);
  90. #endif
  91. #if HAVE_LIBDBMALLOC
  92.     malloc_dump(malloc_errfd);
  93. #elif HAVE_LIBDMALLOC
  94. #elif HAVE_PURIFY
  95.     purify_all_inuse();
  96. #endif
  97. }
  98.  
  99. NCURSES_EXPORT(void)
  100. _nc_free_and_exit(int code)
  101. {
  102.     _nc_freeall();
  103.     exit(code);
  104. }
  105.  
  106. #else
  107. NCURSES_EXPORT(void)
  108. _nc_freeall(void)
  109. {
  110. }
  111. #endif
  112.